class CheckSoureMiddleware(object):
	def __init__(self, get_response):
		self.get_response = get_response

	# One-time configuration and initialization.

	def __call__(self, request):
		# Code to be executed for each request before
		# the view (and later middleware) are called.
		from_source = request.META['HTTP_USER_AGENT']
		print 'from_source:{}'.format(from_source)
		if 'iPhone' in from_source:
			request.session['from_source'] = 'iphone'
		elif 'mobile' in from_source:
			request.session['from_source'] = 'mobile'
		else:
			request.session['from_source'] = 'pc'

		response = self.get_response(request)

		# Code to be executed for each request/response after
		# the view is called.

		return response